package com.sqsf.util;

import com.sqsf.javabean.User;
import mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

public class MyBatisTest{
    public static void main(String[] args) throws IOException {
        //1、加载mybatis核心配置文件创建sqlSessionFactory
        SqlSessionFactory factory = new SqlSessionFactoryBuilder()
                .build(Resources.getResourceAsStream("mybatis-config.xml"));
        //2、创建SqlSession对象
        SqlSession session = factory.openSession();
        //3、调用session的方法namespace的名字.id
        //List<User> users = session.selectList("mapper.UserMapper.selectAllUser");
        //获取指定接口的实现类
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> users = mapper.selectAllUser();
        //4、打印测试
        for(User u:users){
            System.out.println(u);
        }
        //5、关闭资源
        session.close();


    }
}
